/*
 * Created on 24 oct. 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package fr.jade.console.cmd;

import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.NoSuchInterfaceException;

import fr.jade.console.core.AbstractCommand;
import fr.jade.console.core.Command;
import fr.jade.console.core.Environment;
import fr.jade.fraclite.api.control.NoSuchAttributeException;
import fr.jade.fraclite.util.FracLite;

/**
 * @author ssicard
 * 
 */
public class SetAttribute extends AbstractCommand implements Command{

  public String getDescription(){
    return "Set attribute <attName> o component \"curent\" with <attValue>";
  }
  
  public String getHelp(){
    return "setAttribute <attribute Name> <attribute Value>";
  }
  public String getName() {
    return "setatt";
  }
  
	public Object execute(String[] args, Environment env) throws Throwable {
		
		if(args.length == 1){
			System.out.println(getHelp());
		}else if (args[1].equals("-help")){
		  System.out.println(getDescription());
		}else{
		   Component curent = (Component)env.getEnvVar("curent");
		   try {
        FracLite.getAttributeController(curent).setAttribute(args[1], args[2]);
      } catch (NoSuchAttributeException e) {
        System.out.println("No such attribute in curent component");
      } catch (NoSuchInterfaceException e) {
        System.out.println("Curent component is not parametric");
      }
		}
		return null;
	}

}
